package com.yanqu.road.entity.activity.jiuzhou.rank;

import java.util.Comparator;
import java.util.Objects;

/**
 * 九州排序器
 */
public class JiuZhouRankSort implements Comparator<JiuZhouRank>{
    @Override
    public int compare(JiuZhouRank o1, JiuZhouRank o2) {
        if (o2.getValue() != o1.getValue()) {
            return Long.compare(o2.getValue(), o1.getValue());
        }
        // 取较短列表长度作为比较的上限
        int size1 = o1.getParam().size();
        int size2 = o2.getParam().size();
        int minSize = Math.min(size1, size2);

        for (int i = 0; i < minSize; i++) {
            Long param1 = o1.getParam().get(i);
            Long param2 = o2.getParam().get(i);
            if (!Objects.equals(param1, param2)) {
                return Long.compare(param2, param1);
            }
        }
        // 如果一个列表较长，则它应该被认为是较大的，取决于排序规则
        if (size1 != size2) {
            return Integer.compare(size2, size1);
        }
        return Long.compare(o1.getLastUpdateTime(), o2.getLastUpdateTime());
    }
}
